<?php

/**
 *关注回复
 **/
class AreplyAction extends UserAction
{
    public function index()
    {
        $db = D('Areply');
        $where['uid'] = $_SESSION['uid'];
        $where['token'] = $_SESSION['token'];
        $res = $db->where($where)->find();
        $this->assign('areply', $res);
        $this->display();
    }

    public function insert()
    {
        C('TOKEN_ON', false);
        $db = D('Areply');
        $where['uid'] = $_SESSION['uid'];
        $where['token'] = $_SESSION['token'];
        $res = $db->where($where)->find();
        if ($res == false)
        {
            $where['content'] = $this->_post('content');
            if (isset($_POST['keyword']))
            {
                $where['keyword'] = $this->_post('keyword');
            }
            if ($where['content'] == false)
            {
                $this->error('内容必须填写');
            }
            $where['createtime'] = time();
            $id = $db->data($where)->add();
            if ($id)
            {
                $this->success('发布成功', U('Areply/index'));
            } else
            {
                $this->error('发布失败', U('Areply/index'));
            }
        } else
        {
            $where['id'] = $res['id'];
            $where['content'] = $this->_post('content');
            $where['home'] = intval($this->_post('home'));
            $where['updatetime'] = time();
            if (isset($_POST['keyword']))
            {
                $where['keyword'] = $this->_post('keyword');
            }
            if ($db->save($where))
            {
                $this->success('更新成功', U('Areply/index'));
            } else
            {
                $this->error('更新失败', U('Areply/index'));
            }
        }
    }
}

?>